package com.yugao.fintech.draper.admin.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yugao.fintech.draper.admin.entity.SysUserRole;
import com.yugao.fintech.draper.admin.mapper.UserRoleMapper;
import com.yugao.fintech.draper.admin.service.UserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class UserRoleServiceImpl implements UserRoleService {
    @Autowired
    private  UserRoleMapper userRoleMapper;

    @Override
    public void deleteUserRoleByRoleId(Long id) {
        userRoleMapper.delete(Wrappers.<SysUserRole>lambdaQuery().eq(SysUserRole::getRoleId, id));
    }

    @Override
    public void deleteUserRolesByUserIds(List<String> userIds) {
        userRoleMapper.delete(Wrappers.<SysUserRole>lambdaQuery().in(SysUserRole::getUserId, userIds));
    }

    @Override
    public List<SysUserRole> getUserRoleByUserId(Long userId) {
        return userRoleMapper.selectList(Wrappers.<SysUserRole>lambdaQuery().eq(SysUserRole::getUserId, userId));
    }

    @Override
    public void addUserRoles(List<SysUserRole> list) {
        list.forEach(userRoleMapper::insert);
    }

}